import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;

public class UDPServer {
    public static void main(String[] args){
        byte[] inbuff = new byte[1500];
        DatagramPacket inPacket = new DatagramPacket(inbuff, inbuff.length);
        DatagramPacket outPacket;

        try {
            DatagramSocket socket = new DatagramSocket(4396);
            while(true){
                socket.receive(inPacket);
                System.out.println(new String(inPacket.getData(), 0, inPacket.getLength(), StandardCharsets.UTF_8.name()));
                System.out.println(socket.getSoTimeout());
                outPacket = new DatagramPacket(inPacket.getData(), inPacket.getLength(), inPacket.getSocketAddress());
                socket.send(outPacket);
            }
        }  catch (IOException e) {
            e.printStackTrace();
        }
    }
}
